package com.qms.repast.weidgets.common;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qms.repast.R;


/**
 * @author 泅渡者
 * @date 2018/6/25 0025.
 * @describe:
 */

public class CommonLableView extends LinearLayout {
    
    private int resid;
    private String desc;
    private int arrowId;
    
    private ImageView ivIcon;
    private TextView tvDesc;
    private ImageView ivArrow;
    
    public CommonLableView(Context context) {
        super(context);
        initView();
    }
    
    public CommonLableView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }
    
    public CommonLableView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        inItStyleable(context, attrs);
        initView();
    }
    
    private void initView() {
        View.inflate(getContext(), R.layout.layout_common_lable, this);
        ivIcon = findViewById(R.id.iv_icon);
        tvDesc = findViewById(R.id.tv_desc);
        ivArrow = findViewById(R.id.iv_arrow);
        setIcon(resid);
        setDesc(desc);
        setArrow(arrowId);
        
    }
    
    private void inItStyleable(Context context, AttributeSet attrs) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CommonLableView);
        resid = a.getResourceId(R.styleable.CommonLableView_view_icon, R.mipmap.ic_launcher);
        desc = a.getString(R.styleable.CommonLableView_view_desc);
        arrowId = a.getResourceId(R.styleable.CommonLableView_view_arrow, R.mipmap.ic_launcher);
        a.recycle();
    }
    
    private void setArrow(int arrowId) {
        ivArrow.setImageResource(arrowId);
    }
    
    private void setDesc(String desc) {
        tvDesc.setText(desc);
    }
    
    private void setIcon(int resid) {
        ivIcon.setImageResource(resid);
    }
    
    
}
